package com.appkubes.mall.restful.application.activity.apply.service.impl;

import com.appkubes.mall.core.entity.MallGoodsTaobao;
import com.appkubes.mall.core.service.impl.BaseMallActivityApplyServiceImpl;
import com.appkubes.mall.restful.application.activity.apply.dao.ApplyDao;
import com.appkubes.mall.restful.application.activity.apply.entity.dto.ApplyListDTO;
import com.appkubes.mall.restful.application.activity.apply.entity.vo.ApplyListVO;
import com.appkubes.mall.restful.application.activity.apply.service.ActivityApplyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Lin Jiaming
 * @Date: 2020/3/6
 * @Description:
 */
@Service
public class ActivityApplyServiceImpl extends BaseMallActivityApplyServiceImpl implements ActivityApplyService {

    @Autowired
    ApplyDao applyDao;

    @Override
    public IPage<ApplyListDTO> applyList(ApplyListVO applyListVO) {
        Page page = new Page(applyListVO.getPage(),applyListVO.getSize());

        QueryWrapper<MallGoodsTaobao> wrapper = new QueryWrapper<>();
        if(applyListVO.getCid()!=null){
            wrapper.eq("cid",applyListVO.getCid());
        }
        if(applyListVO.getMinPrice() != null){
            wrapper.ge("actual_price",applyListVO.getMinPrice());
        }
        if(applyListVO.getMaxPrice() != null){
            wrapper.le("actual_price",applyListVO.getMaxPrice());
        }
        if(applyListVO.getMinCoupon() != null){
            wrapper.ge("coupon_price",applyListVO.getMinCoupon());
        }
        if(applyListVO.getMaxCoupon() != null){
            wrapper.le("coupon_price",applyListVO.getMaxCoupon());
        }
        if(applyListVO.getTkRate() != null){
            wrapper.ge("commission_rate",applyListVO.getTkRate());
        }
        if(applyListVO.getSort() != null){
            switch (applyListVO.getSort()){
                case "zx"://最新
                    wrapper.orderByDesc("create_time");
                    break;
                case "sell"://销量
                    wrapper.orderByDesc("month_sales");
                    break;
                case "lql"://领券量
                    wrapper.orderByDesc("coupon_receive_num");
                    break;
                case "yj"://佣金
                    wrapper.orderByDesc("commission_rate");
                    break;
                case "jgdown"://佣金降序
                    wrapper.orderByDesc("actual_price");
                    break;
                case "jgup"://佣金升序
                    wrapper.orderByAsc("actual_price");
                    break;
                case "zh"://综合
                    break;
            }
        }

        return applyDao.applyList(page,wrapper);
    }
}
